package com.ktjy.ktmall.service.impl;


import com.ktjy.ktmall.dao.TMenuDao;
import com.ktjy.ktmall.dao.impl.TMenuDaoImpl;
import com.ktjy.ktmall.entity.Menu;
import com.ktjy.ktmall.service.TMenuService;

import java.util.ArrayList;
import java.util.List;


public class TMenuServiceImpl implements TMenuService {
    //创建一个菜单对象
    TMenuDao tMenuDao=new TMenuDaoImpl();
    @Override
    public List<Menu> getMenus() {
        List<Menu> list = tMenuDao.getMenuList();

        for (int i=0;i<list.size();i++){
            Menu menu=list.get(i);
            List<Menu> children=menu.getChildren();
            if(children==null){
                children=new ArrayList<>();
            }

            for (Menu menu1 : list){
                if(menu1.getPs_pid()==menu.getPs_id()){
                    children.add(menu1);
                }
            }
            menu.setChildren(children);
        }

        List<Menu> result=new ArrayList<>();
        for (Menu menu : list){
            if(menu.getPs_pid()==0){
                result.add(menu);
            }
        }
        return result;
    }
}
